// 切换css
export function changeTheme(theme: string) {
  document.getElementById("ant-style")?.remove();
  const nodes = document.head.childNodes;
  const styleDom = document.createElement("style");
  styleDom.id = "ant-style";
  styleDom.innerHTML = theme;
  document.head.insertBefore(styleDom, nodes[0]);
}

// 切换黑暗模式或者白天模式
export async function toggleDarkMode(isDark: boolean) {
  let lessModule: any;
  if (isDark) {
    lessModule = () => import(`./dark.less?inline`);
  } else {
    lessModule = () => import(`./light.less?inline`);
  }
  const content = await lessModule();
  changeTheme(content.default);
}
